.class public Lcom/teewoo/app/bus/manager/history/StationHistoryManager;
.super Ljava/lang/Object;
.source "StationHistoryManager.java"


# instance fields
.field private dbInstance:Lcom/teewoo/app/bus/db/history/StationHistoryDBHelper;


# direct methods
.method public constructor <init>(Landroid/content/Context;)V
    .locals 1
    .parameter "context"

    .prologue
    .line 20
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    .line 21
    new-instance v0, Lcom/teewoo/app/bus/db/history/StationHistoryDBHelper;

    invoke-direct {v0, p1}, Lcom/teewoo/app/bus/db/history/StationHistoryDBHelper;-><init>(Landroid/content/Context;)V

    iput-object v0, p0, Lcom/teewoo/app/bus/manager/history/StationHistoryManager;->dbInstance:Lcom/teewoo/app/bus/db/history/StationHistoryDBHelper;

    .line 22
    return-void
.end method


# virtual methods
.method public delete(Ljava/lang/Integer;)V
    .locals 4
    .parameter "id"

    .prologue
    .line 42
    iget-object v1, p0, Lcom/teewoo/app/bus/manager/history/StationHistoryManager;->dbInstance:Lcom/teewoo/app/bus/db/history/StationHistoryDBHelper;

    invoke-virtual {v1}, Lcom/teewoo/app/bus/db/history/StationHistoryDBHelper;->getWritableDatabase()Landroid/database/sqlite/SQLiteDatabase;

    move-result-object v0

    .line 43
    .local v0, database:Landroid/database/sqlite/SQLiteDatabase;
    const-string v1, "delete from station_history where _id in =?"

    const/4 v2, 0x1

    new-array v2, v2, [Ljava/lang/Object;

    const/4 v3, 0x0

    aput-object p1, v2, v3

    invoke-virtual {v0, v1, v2}, Landroid/database/sqlite/SQLiteDatabase;->execSQL(Ljava/lang/String;[Ljava/lang/Object;)V

    .line 44
    invoke-virtual {v0}, Landroid/database/sqlite/SQLiteDatabase;->close()V

    .line 45
    return-void
.end method

.method public deleteAll()V
    .locals 3

    .prologue
    .line 52
    iget-object v1, p0, Lcom/teewoo/app/bus/manager/history/StationHistoryManager;->dbInstance:Lcom/teewoo/app/bus/db/history/StationHistoryDBHelper;

    invoke-virtual {v1}, Lcom/teewoo/app/bus/db/history/StationHistoryDBHelper;->getWritableDatabase()Landroid/database/sqlite/SQLiteDatabase;

    move-result-object v0

    .line 53
    .local v0, database:Landroid/database/sqlite/SQLiteDatabase;
    const-string v1, "delete from station_history"

    const/4 v2, 0x0

    new-array v2, v2, [Ljava/lang/Object;

    invoke-virtual {v0, v1, v2}, Landroid/database/sqlite/SQLiteDatabase;->execSQL(Ljava/lang/String;[Ljava/lang/Object;)V

    .line 54
    invoke-virtual {v0}, Landroid/database/sqlite/SQLiteDatabase;->close()V

    .line 55
    return-void
.end method

.method public find(I)Lcom/teewoo/app/bus/model/history/StationHistory;
    .locals 8
    .parameter "stationId"

    .prologue
    const/4 v7, 0x1

    const/4 v6, 0x0

    .line 76
    iget-object v3, p0, Lcom/teewoo/app/bus/manager/history/StationHistoryManager;->dbInstance:Lcom/teewoo/app/bus/db/history/StationHistoryDBHelper;

    invoke-virtual {v3}, Lcom/teewoo/app/bus/db/history/StationHistoryDBHelper;->getWritableDatabase()Landroid/database/sqlite/SQLiteDatabase;

    move-result-object v1

    .line 77
    .local v1, database:Landroid/database/sqlite/SQLiteDatabase;
    const/4 v2, 0x0

    .line 79
    .local v2, tempHis:Lcom/teewoo/app/bus/model/history/StationHistory;
    const-string v3, "select * from station_history where station_id = ?"

    .line 80
    new-array v4, v7, [Ljava/lang/String;

    invoke-static {p1}, Ljava/lang/String;->valueOf(I)Ljava/lang/String;

    move-result-object v5

    aput-object v5, v4, v6

    .line 78
    invoke-virtual {v1, v3, v4}, Landroid/database/sqlite/SQLiteDatabase;->rawQuery(Ljava/lang/String;[Ljava/lang/String;)Landroid/database/Cursor;

    move-result-object v0

    .line 81
    .local v0, cursor:Landroid/database/Cursor;
    invoke-interface {v0}, Landroid/database/Cursor;->moveToFirst()Z

    move-result v3

    if-eqz v3, :cond_0

    .line 82
    new-instance v2, Lcom/teewoo/app/bus/model/history/StationHistory;

    .end local v2           #tempHis:Lcom/teewoo/app/bus/model/history/StationHistory;
    invoke-interface {v0, v6}, Landroid/database/Cursor;->getInt(I)I

    move-result v3

    invoke-static {v3}, Ljava/lang/Integer;->valueOf(I)Ljava/lang/Integer;

    move-result-object v3

    invoke-interface {v0, v7}, Landroid/database/Cursor;->getString(I)Ljava/lang/String;

    move-result-object v4

    .line 83
    const/4 v5, 0x2

    invoke-interface {v0, v5}, Landroid/database/Cursor;->getInt(I)I

    move-result v5

    invoke-static {v5}, Ljava/lang/Integer;->valueOf(I)Ljava/lang/Integer;

    move-result-object v5

    const/4 v6, 0x3

    invoke-interface {v0, v6}, Landroid/database/Cursor;->getString(I)Ljava/lang/String;

    move-result-object v6

    .line 82
    invoke-direct {v2, v3, v4, v5, v6}, Lcom/teewoo/app/bus/model/history/StationHistory;-><init>(Ljava/lang/Integer;Ljava/lang/String;Ljava/lang/Integer;Ljava/lang/String;)V

    .line 85
    .restart local v2       #tempHis:Lcom/teewoo/app/bus/model/history/StationHistory;
    :cond_0
    invoke-interface {v0}, Landroid/database/Cursor;->close()V

    .line 86
    invoke-virtual {v1}, Landroid/database/sqlite/SQLiteDatabase;->close()V

    .line 87
    return-object v2
.end method

.method public findByKeyword(Ljava/lang/String;)Lcom/teewoo/app/bus/model/history/StationHistory;
    .locals 7
    .parameter "keyWord"

    .prologue
    const/4 v6, 0x1

    const/4 v5, 0x0

    .line 97
    iget-object v3, p0, Lcom/teewoo/app/bus/manager/history/StationHistoryManager;->dbInstance:Lcom/teewoo/app/bus/db/history/StationHistoryDBHelper;

    invoke-virtual {v3}, Lcom/teewoo/app/bus/db/history/StationHistoryDBHelper;->getWritableDatabase()Landroid/database/sqlite/SQLiteDatabase;

    move-result-object v1

    .line 98
    .local v1, database:Landroid/database/sqlite/SQLiteDatabase;
    const/4 v2, 0x0

    .line 100
    .local v2, tempHis:Lcom/teewoo/app/bus/model/history/StationHistory;
    const-string v3, "select * from station_history where keyword = ?"

    .line 101
    new-array v4, v6, [Ljava/lang/String;

    aput-object p1, v4, v5

    .line 99
    invoke-virtual {v1, v3, v4}, Landroid/database/sqlite/SQLiteDatabase;->rawQuery(Ljava/lang/String;[Ljava/lang/String;)Landroid/database/Cursor;

    move-result-object v0

    .line 102
    .local v0, cursor:Landroid/database/Cursor;
    invoke-interface {v0}, Landroid/database/Cursor;->moveToFirst()Z

    move-result v3

    if-eqz v3, :cond_0

    .line 103
    new-instance v2, Lcom/teewoo/app/bus/model/history/StationHistory;

    .end local v2           #tempHis:Lcom/teewoo/app/bus/model/history/StationHistory;
    invoke-interface {v0, v5}, Landroid/database/Cursor;->getInt(I)I

    move-result v3

    invoke-static {v3}, Ljava/lang/Integer;->valueOf(I)Ljava/lang/Integer;

    move-result-object v3

    invoke-interface {v0, v6}, Landroid/database/Cursor;->getString(I)Ljava/lang/String;

    move-result-object v4

    .line 104
    const/4 v5, 0x2

    invoke-interface {v0, v5}, Landroid/database/Cursor;->getInt(I)I

    move-result v5

    invoke-static {v5}, Ljava/lang/Integer;->valueOf(I)Ljava/lang/Integer;

    move-result-object v5

    const/4 v6, 0x3

    invoke-interface {v0, v6}, Landroid/database/Cursor;->getString(I)Ljava/lang/String;

    move-result-object v6

    .line 103
    invoke-direct {v2, v3, v4, v5, v6}, Lcom/teewoo/app/bus/model/history/StationHistory;-><init>(Ljava/lang/Integer;Ljava/lang/String;Ljava/lang/Integer;Ljava/lang/String;)V

    .line 106
    .restart local v2       #tempHis:Lcom/teewoo/app/bus/model/history/StationHistory;
    :cond_0
    invoke-interface {v0}, Landroid/database/Cursor;->close()V

    .line 107
    invoke-virtual {v1}, Landroid/database/sqlite/SQLiteDatabase;->close()V

    .line 108
    return-object v2
.end method

.method public getAll()Ljava/util/List;
    .locals 9
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "()",
            "Ljava/util/List",
            "<",
            "Lcom/teewoo/app/bus/model/history/StationHistory;",
            ">;"
        }
    .end annotation

    .prologue
    const/4 v8, 0x0

    .line 120
    new-instance v2, Ljava/util/ArrayList;

    invoke-direct {v2}, Ljava/util/ArrayList;-><init>()V

    .line 121
    .local v2, list:Ljava/util/List;,"Ljava/util/List<Lcom/teewoo/app/bus/model/history/StationHistory;>;"
    iget-object v3, p0, Lcom/teewoo/app/bus/manager/history/StationHistoryManager;->dbInstance:Lcom/teewoo/app/bus/db/history/StationHistoryDBHelper;

    invoke-virtual {v3}, Lcom/teewoo/app/bus/db/history/StationHistoryDBHelper;->getWritableDatabase()Landroid/database/sqlite/SQLiteDatabase;

    move-result-object v1

    .line 124
    .local v1, database:Landroid/database/sqlite/SQLiteDatabase;
    const-string v3, "select * from station_history ORDER BY search_time DESC"

    .line 125
    new-array v4, v8, [Ljava/lang/String;

    .line 123
    invoke-virtual {v1, v3, v4}, Landroid/database/sqlite/SQLiteDatabase;->rawQuery(Ljava/lang/String;[Ljava/lang/String;)Landroid/database/Cursor;

    move-result-object v0

    .line 127
    .local v0, cursor:Landroid/database/Cursor;
    :goto_0
    invoke-interface {v0}, Landroid/database/Cursor;->moveToNext()Z

    move-result v3

    if-nez v3, :cond_0

    .line 131
    invoke-interface {v0}, Landroid/database/Cursor;->close()V

    .line 132
    invoke-virtual {v1}, Landroid/database/sqlite/SQLiteDatabase;->close()V

    .line 133
    return-object v2

    .line 129
    :cond_0
    new-instance v3, Lcom/teewoo/app/bus/model/history/StationHistory;

    invoke-interface {v0, v8}, Landroid/database/Cursor;->getInt(I)I

    move-result v4

    invoke-static {v4}, Ljava/lang/Integer;->valueOf(I)Ljava/lang/Integer;

    move-result-object v4

    const/4 v5, 0x1

    invoke-interface {v0, v5}, Landroid/database/Cursor;->getString(I)Ljava/lang/String;

    move-result-object v5

    const/4 v6, 0x2

    invoke-interface {v0, v6}, Landroid/database/Cursor;->getInt(I)I

    move-result v6

    invoke-static {v6}, Ljava/lang/Integer;->valueOf(I)Ljava/lang/Integer;

    move-result-object v6

    const/4 v7, 0x3

    invoke-interface {v0, v7}, Landroid/database/Cursor;->getString(I)Ljava/lang/String;

    move-result-object v7

    invoke-direct {v3, v4, v5, v6, v7}, Lcom/teewoo/app/bus/model/history/StationHistory;-><init>(Ljava/lang/Integer;Ljava/lang/String;Ljava/lang/Integer;Ljava/lang/String;)V

    invoke-interface {v2, v3}, Ljava/util/List;->add(Ljava/lang/Object;)Z

    goto :goto_0
.end method

.method public getCount()J
    .locals 4

    .prologue
    .line 164
    iget-object v2, p0, Lcom/teewoo/app/bus/manager/history/StationHistoryManager;->dbInstance:Lcom/teewoo/app/bus/db/history/StationHistoryDBHelper;

    invoke-virtual {v2}, Lcom/teewoo/app/bus/db/history/StationHistoryDBHelper;->getWritableDatabase()Landroid/database/sqlite/SQLiteDatabase;

    move-result-object v1

    .line 166
    .local v1, database:Landroid/database/sqlite/SQLiteDatabase;
    const-string v2, "select count(*) from station_history"

    const/4 v3, 0x0

    .line 165
    invoke-virtual {v1, v2, v3}, Landroid/database/sqlite/SQLiteDatabase;->rawQuery(Ljava/lang/String;[Ljava/lang/String;)Landroid/database/Cursor;

    move-result-object v0

    .line 167
    .local v0, cursor:Landroid/database/Cursor;
    invoke-interface {v0}, Landroid/database/Cursor;->moveToNext()Z

    move-result v2

    if-eqz v2, :cond_0

    .line 168
    invoke-virtual {v1}, Landroid/database/sqlite/SQLiteDatabase;->close()V

    .line 169
    const/4 v2, 0x0

    invoke-interface {v0, v2}, Landroid/database/Cursor;->getLong(I)J

    move-result-wide v2

    .line 172
    :goto_0
    return-wide v2

    .line 171
    :cond_0
    invoke-virtual {v1}, Landroid/database/sqlite/SQLiteDatabase;->close()V

    .line 172
    const-wide/16 v2, 0x0

    goto :goto_0
.end method

.method public getRawAll()Landroid/database/Cursor;
    .locals 5

    .prologue
    .line 144
    iget-object v3, p0, Lcom/teewoo/app/bus/manager/history/StationHistoryManager;->dbInstance:Lcom/teewoo/app/bus/db/history/StationHistoryDBHelper;

    invoke-virtual {v3}, Lcom/teewoo/app/bus/db/history/StationHistoryDBHelper;->getReadableDatabase()Landroid/database/sqlite/SQLiteDatabase;

    move-result-object v1

    .line 145
    .local v1, database:Landroid/database/sqlite/SQLiteDatabase;
    const/4 v2, 0x0

    .line 149
    .local v2, tempCur:Landroid/database/Cursor;
    const-string v3, "select * from station_history ORDER BY search_time DESC"

    .line 150
    const/4 v4, 0x0

    new-array v4, v4, [Ljava/lang/String;

    .line 148
    invoke-virtual {v1, v3, v4}, Landroid/database/sqlite/SQLiteDatabase;->rawQuery(Ljava/lang/String;[Ljava/lang/String;)Landroid/database/Cursor;

    move-result-object v0

    .line 152
    .local v0, cursor:Landroid/database/Cursor;
    invoke-interface {v0}, Landroid/database/Cursor;->moveToFirst()Z

    move-result v3

    if-eqz v3, :cond_0

    .line 153
    move-object v2, v0

    .line 155
    :cond_0
    invoke-interface {v0}, Landroid/database/Cursor;->close()V

    .line 156
    invoke-virtual {v1}, Landroid/database/sqlite/SQLiteDatabase;->close()V

    .line 157
    return-object v2
.end method

.method public save(Lcom/teewoo/app/bus/model/history/StationHistory;)V
    .locals 5
    .parameter "staHistory"

    .prologue
    .line 30
    iget-object v1, p0, Lcom/teewoo/app/bus/manager/history/StationHistoryManager;->dbInstance:Lcom/teewoo/app/bus/db/history/StationHistoryDBHelper;

    invoke-virtual {v1}, Lcom/teewoo/app/bus/db/history/StationHistoryDBHelper;->getWritableDatabase()Landroid/database/sqlite/SQLiteDatabase;

    move-result-object v0

    .line 31
    .local v0, database:Landroid/database/sqlite/SQLiteDatabase;
    const-string v1, "insert into station_history ( keyword, station_id, search_time) values ( ?, ?, ?);"

    .line 32
    const/4 v2, 0x3

    new-array v2, v2, [Ljava/lang/Object;

    const/4 v3, 0x0

    invoke-virtual {p1}, Lcom/teewoo/app/bus/model/history/StationHistory;->getKeyWord()Ljava/lang/String;

    move-result-object v4

    aput-object v4, v2, v3

    const/4 v3, 0x1

    invoke-virtual {p1}, Lcom/teewoo/app/bus/model/history/StationHistory;->getStationId()Ljava/lang/Integer;

    move-result-object v4

    aput-object v4, v2, v3

    const/4 v3, 0x2

    invoke-virtual {p1}, Lcom/teewoo/app/bus/model/history/StationHistory;->getSearchTime()Ljava/lang/String;

    move-result-object v4

    aput-object v4, v2, v3

    .line 31
    invoke-virtual {v0, v1, v2}, Landroid/database/sqlite/SQLiteDatabase;->execSQL(Ljava/lang/String;[Ljava/lang/Object;)V

    .line 33
    invoke-virtual {v0}, Landroid/database/sqlite/SQLiteDatabase;->close()V

    .line 34
    return-void
.end method

.method public update(Lcom/teewoo/app/bus/model/history/StationHistory;)V
    .locals 5
    .parameter "staHistory"

    .prologue
    .line 63
    iget-object v1, p0, Lcom/teewoo/app/bus/manager/history/StationHistoryManager;->dbInstance:Lcom/teewoo/app/bus/db/history/StationHistoryDBHelper;

    invoke-virtual {v1}, Lcom/teewoo/app/bus/db/history/StationHistoryDBHelper;->getWritableDatabase()Landroid/database/sqlite/SQLiteDatabase;

    move-result-object v0

    .line 64
    .local v0, database:Landroid/database/sqlite/SQLiteDatabase;
    const-string v1, "update station_history set keyword = ?, station_id = ?, search_time = ? where _id=?"

    .line 65
    const/4 v2, 0x4

    new-array v2, v2, [Ljava/lang/Object;

    const/4 v3, 0x0

    invoke-virtual {p1}, Lcom/teewoo/app/bus/model/history/StationHistory;->getKeyWord()Ljava/lang/String;

    move-result-object v4

    aput-object v4, v2, v3

    const/4 v3, 0x1

    invoke-virtual {p1}, Lcom/teewoo/app/bus/model/history/StationHistory;->getStationId()Ljava/lang/Integer;

    move-result-object v4

    aput-object v4, v2, v3

    const/4 v3, 0x2

    invoke-virtual {p1}, Lcom/teewoo/app/bus/model/history/StationHistory;->getSearchTime()Ljava/lang/String;

    move-result-object v4

    aput-object v4, v2, v3

    const/4 v3, 0x3

    invoke-virtual {p1}, Lcom/teewoo/app/bus/model/history/StationHistory;->getId()Ljava/lang/Integer;

    move-result-object v4

    aput-object v4, v2, v3

    .line 64
    invoke-virtual {v0, v1, v2}, Landroid/database/sqlite/SQLiteDatabase;->execSQL(Ljava/lang/String;[Ljava/lang/Object;)V

    .line 66
    invoke-virtual {v0}, Landroid/database/sqlite/SQLiteDatabase;->close()V

    .line 67
    return-void
.end method
